# -*- coding: utf-8 -*-
import sys
sys.path.append("Controller")
sys.path.append("Data")
sys.path.append("Model")
sys.path.append("View")
from cont_insert_bdd import CLS_ContlInsertBdd
from cont_read_xls import CLS_ContlReadXls
from cont_plot_img import CLS_Contlr_App_Plot
from cont_queries import CLS_Contlr_Queries
from cont_write_csv import CLS_Contlr_Write_Csv
#from view_plot_data import AppPlot

def main():

	print "\n\nSTART APPLICATION ?\n\nY - Yes\nN - No\n"

	#charInConsole = raw_input()
	charInConsole = 'Y'
	if charInConsole == 'Y':

		openXls = CLS_ContlReadXls()
	   	xlsSheetToBdd = openXls.funcContlReadXls()

	   	appMakeBdd = CLS_ContlInsertBdd()	

		if appMakeBdd.funcMakeDataBase(xlsSheetToBdd) == True:

			#raw_input("\n\nData inserted in BDD ...\n\nANY KEY TO CONTINUE ...")

			## QUERIES
			statistics = CLS_Contlr_Queries()
			lista1 = statistics.query1()
			lista2 = statistics.query2()
			lista3 = statistics.query3()
			lista4 = statistics.query4()
			## CSV Writer
			csv_writer = CLS_Contlr_Write_Csv()
			csv_writer.statistics_to_csv(lista1, lista2, lista3, lista4)
			## DRAW QUERY 1
			drawPlot = CLS_Contlr_App_Plot()
			curso = '5301 - Engenharia Informática e de Computadores'
			unidade = '0807 - Instituto Superior Técnico'
			drawPlot.stats_query(lista2, curso, unidade)
			## DRAW QUERY 2
			nivel = 'L - Licenciatura'
			drawPlot.stats_query4(lista4, nivel)
			'''
			strTitlePplot = "XXXXX XXXXX XXXXX XXXXX XXXXX"
			listNameX = ['control', 'cold treatment',
			                 'hot treatment', 'another treatment',
			                 'the last one']
			ValueX = 0
			listNameY = 0
			listValueY = [4, 6, 7, 3, 5]
			strLabelY = 'Counts'

			drawPlotImg = drawPlot.funcModlAppPlot(
				strTitlePplot, listNameX, 
				ValueX, listNameY,
				listValueY, strLabelY
				)
			'''
			#drawPlotImg = drawPlot.plotImg(strTitlePplot)
			#drawPlot.plotImg(womenMeans, strTitlePplot, labelX, labelY, xTickLabels)

			raw_input("\n\nPLOT OK ...\n\nANY KEY TO CONTINUE ...")

			#queryBdd = CLS_ModlQuery1()
			#runQueryBdd = queryBdd.funcModlQuery1()

		else:
		
			raw_input("\n\nANY KEY TO EXIT ...")
			sys.exit()

	elif charInConsole == 'N':

	    raw_input("\n\nANY KEY TO EXIT ...")

	elif (charInConsole != 'N') and (charInConsole != 'N'):

		raw_input("\n\n(Y)es or (N)o ...\n\nANY KEY TO CONTINUE ...")
		main()

	else:
		sys.exit()

main()
